package 栈题.有效的括号;

import 栈的数组实现.Stack2;

public class Test {

    public static boolean isValid(String s) {
        Stack2<Character> stack = new Stack2<>(s.length());
        for (int i = 0; i < s.length(); i++) {
            switch (s.charAt(i)) {
                case '(': stack.push(')');break;
                case '[': stack.push(']');break;
                case '{': stack.push('}');break;
                case ')': if (stack.pop() == ')') break; return false;
                case ']': if (stack.pop() == ']') break; return false;
                case '}': if (stack.pop() == '}') break; return false;

            }
        }
        return stack.pop() == null;
    }

    public static void main(String[] args) {
        String s = "([{}])";
        String s1 = "([{]})";
        String s2 = "([{])";
        System.out.println(isValid(s));
        System.out.println(isValid(s1));
        System.out.println(isValid(s2));
    }
}
